package com.cheyunkeji.er.activity.auction;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.Constants;
import com.cheyunkeji.er.activity.evaluate.PhotoPreViewActivity;
import com.cheyunkeji.er.adapter.ViewPagerAdapter;
import com.cheyunkeji.er.base.BaseActivity;
import com.cheyunkeji.er.bean.evaluate.EvaluateDetailResult2;
import com.cheyunkeji.er.utils.BitmapUtils;
import com.cheyunkeji.er.utils.ConvertUtils;
import com.cheyunkeji.er.utils.ScreenUtil;
import com.cheyunkeji.er.utils.ToastUtil;
import com.cheyunkeji.er.view.AutoScrollViewPager;
import com.cheyunkeji.er.view.TabTitle;
import com.cheyunkeji.er.view.TopBar;
import com.cheyunkeji.er.view.auction.CarArchiveItemView;
import com.cheyunkeji.er.view.evaluate.DrawBitmapsImageView;
import com.google.gson.Gson;

import java.util.ArrayList;

import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;

public class CarEvaluateDetailActivity extends BaseActivity implements ViewPager.OnPageChangeListener, CarArchiveItemView.OnPhotoIconClickListener {


    private static final String TAG = CarEvaluateDetailActivity.class.getSimpleName();
    @BindView(R.id.v_topbar)
    TopBar vTopbar;
    @BindView(R.id.tt_accident_check)
    TabTitle ttAccidentCheck;
    @BindView(R.id.caiv_right_c)
    CarArchiveItemView caivRightC;
    @BindView(R.id.ll_accident_check)
    LinearLayout llAccidentCheck;
    @BindView(R.id.sv_content)
    ScrollView svContent;
    @BindView(R.id.activity_car_archive)
    LinearLayout activityCarArchive;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.caiv_right_a)
    CarArchiveItemView caivRightA;
    @BindView(R.id.caiv_right_b)
    CarArchiveItemView caivRightB;
    @BindView(R.id.caiv_yhxg)
    CarArchiveItemView caivYhxg;
    @BindView(R.id.caiv_left_c)
    CarArchiveItemView caivLeftC;
    @BindView(R.id.caiv_zhxg)
    CarArchiveItemView caivZhxg;
    @BindView(R.id.caiv_left_b)
    CarArchiveItemView caivLeftB;
    @BindView(R.id.caiv_left_a)
    CarArchiveItemView caivLeftA;
    @BindView(R.id.caiv_zqzl)
    CarArchiveItemView caivZqzl;
    @BindView(R.id.caiv_zyl)
    CarArchiveItemView caivZyl;
    @BindView(R.id.caiv_zqxg)
    CarArchiveItemView caivZqxg;
    @BindView(R.id.caiv_lmj)
    CarArchiveItemView caivLmj;
    @BindView(R.id.caiv_yyl)
    CarArchiveItemView caivYyl;
    @BindView(R.id.caiv_yqzl)
    CarArchiveItemView caivYqzl;
    @BindView(R.id.caiv_yqxg)
    CarArchiveItemView caivYqxg;
    @BindView(R.id.caiv_ctzydc)
    CarArchiveItemView caivCtzydc;
    @BindView(R.id.caiv_hfzlss)
    CarArchiveItemView caivHfzlss;
    @BindView(R.id.caiv_gzlax)
    CarArchiveItemView caivGzlax;
    @BindView(R.id.caiv_gzlwgd)
    CarArchiveItemView caivGzlwgd;
    @BindView(R.id.caiv_gzlbx)
    CarArchiveItemView caivGzlbx;
    @BindView(R.id.caiv_gzlsx)
    CarArchiveItemView caivGzlsx;
    @BindView(R.id.caiv_cnjs)
    CarArchiveItemView caivCnjs;
    @BindView(R.id.caiv_btsyjs)
    CarArchiveItemView caivBtsyjs;
    @BindView(R.id.caiv_cdpsx)
    CarArchiveItemView caivCdpsx;
    @BindView(R.id.caiv_nzntdcsx)
    CarArchiveItemView caivNzntdcsx;
    @BindView(R.id.caiv_cksysh)
    CarArchiveItemView caivCksysh;
    @BindView(R.id.tt_appearance_check)
    TabTitle ttAppearanceCheck;
    @BindView(R.id.asvp_img_display)
    AutoScrollViewPager asvpImgDisplay;
    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.tv_indicator)
    TextView tvIndicator;
    @BindView(R.id.ll_appearance_check)
    LinearLayout llAppearanceCheck;
    @BindView(R.id.tt_lacquer_check)
    TabTitle ttLacquerCheck;
    @BindView(R.id.ll_lacquer_check)
    LinearLayout llLacquerCheck;
    @BindView(R.id.tt_commonuse_check)
    TabTitle ttCommonuseCheck;
    @BindView(R.id.caiv_jyhrlqy)
    CarArchiveItemView caivJyhrlqy;
    @BindView(R.id.caiv_ggwjysl)
    CarArchiveItemView caivGgwjysl;
    @BindView(R.id.caiv_srqgsps)
    CarArchiveItemView caivSrqgsps;
    @BindView(R.id.caiv_xdcdjzzfs)
    CarArchiveItemView caivXdcdjzzfs;
    @BindView(R.id.caiv_xdcdjyslqs)
    CarArchiveItemView caivXdcdjyslqs;
    @BindView(R.id.caiv_fdjpdlh)
    CarArchiveItemView caivFdjpdlh;
    @BindView(R.id.caiv_yglhls)
    CarArchiveItemView caivYglhls;
    @BindView(R.id.caiv_sglhls)
    CarArchiveItemView caivSglhls;
    @BindView(R.id.caiv_xslhps)
    CarArchiveItemView caivXslhps;
    @BindView(R.id.caiv_fdjhmwfqr)
    CarArchiveItemView caivFdjhmwfqr;
    @BindView(R.id.caiv_cnpshj)
    CarArchiveItemView caivCnpshj;
    @BindView(R.id.caiv_cnhsjps)
    CarArchiveItemView caivCnhsjps;
    @BindView(R.id.caiv_cnyyw)
    CarArchiveItemView caivCnyyw;
    @BindView(R.id.caiv_ybtyyc)
    CarArchiveItemView caivYbtyyc;
    @BindView(R.id.caiv_tcqbyc)
    CarArchiveItemView caivTcqbyc;
    @BindView(R.id.caiv_tcmftlh)
    CarArchiveItemView caivTcmftlh;
    @BindView(R.id.caiv_zczdxtyc)
    CarArchiveItemView caivZczdxtyc;
    @BindView(R.id.caiv_jsczkyp)
    CarArchiveItemView caivJsczkyp;
    @BindView(R.id.caiv_yxzj)
    CarArchiveItemView caivYxzj;
    @BindView(R.id.caiv_clqdbsc)
    CarArchiveItemView caivClqdbsc;
    @BindView(R.id.caiv_ybbzsdyc)
    CarArchiveItemView caivYbbzsdyc;
    @BindView(R.id.caiv_fxdtdsnd)
    CarArchiveItemView caivFxdtdsnd;
    @BindView(R.id.caiv_tjgnbzc)
    CarArchiveItemView caivTjgnbzc;
    @BindView(R.id.caiv_bcfzxtgzbzc)
    CarArchiveItemView caivBcfzxtgzbzc;
    @BindView(R.id.caiv_abs_unnormal)
    CarArchiveItemView caivAbsUnnormal;
    @BindView(R.id.caiv_ktgz)
    CarArchiveItemView caivKtgz;
    @BindView(R.id.caiv_ktxtblr)
    CarArchiveItemView caivKtxtblr;
    @BindView(R.id.caiv_fdjdsyzbwd)
    CarArchiveItemView caivFdjdsyzbwd;
    @BindView(R.id.caiv_fdjyyx)
    CarArchiveItemView caivFdjyyx;
    @BindView(R.id.caiv_fdjyyy_clpqbzc)
    CarArchiveItemView caivFdjyyyClpqbzc;
    @BindView(R.id.caiv_fdjjsbzc)
    CarArchiveItemView caivFdjjsbzc;
    @BindView(R.id.caiv_jsyppxx)
    CarArchiveItemView caivJsyppxx;
    @BindView(R.id.caiv_zdxtgzbzc)
    CarArchiveItemView caivZdxtgzbzc;
    @BindView(R.id.caiv_bsxgzbzc)
    CarArchiveItemView caivBsxgzbzc;
    @BindView(R.id.caiv_xcgcz_cldpyyx)
    CarArchiveItemView caivXcgczCldpyyx;
    @BindView(R.id.caiv_xsgcz_clzxbwyyx)
    CarArchiveItemView caivXsgczClzxbwyyx;
    @BindView(R.id.caiv_xsfxphdd)
    CarArchiveItemView caivXsfxphdd;
    @BindView(R.id.caiv_kktsfd_jwtsxx)
    CarArchiveItemView caivKktsfdJwtsxx;
    @BindView(R.id.caiv_fdjydksl)
    CarArchiveItemView caivFdjydksl;
    @BindView(R.id.caiv_bsxtsl)
    CarArchiveItemView caivBsxtsl;
    @BindView(R.id.caiv_zxjbqxsd)
    CarArchiveItemView caivZxjbqxsd;
    @BindView(R.id.caiv_sjbqxsd)
    CarArchiveItemView caivSjbqxsd;
    @BindView(R.id.caiv_cdzszjsk)
    CarArchiveItemView caivCdzszjsk;
    @BindView(R.id.caiv_jzqsy)
    CarArchiveItemView caivJzqsy;
    @BindView(R.id.caiv_jzthsh)
    CarArchiveItemView caivJzthsh;
    @BindView(R.id.caiv_cdpzjdjsx)
    CarArchiveItemView caivCdpzjdjsx;
    @BindView(R.id.caiv_pqghxyq_yyhpl)
    CarArchiveItemView caivPqghxyqYyhpl;
    @BindView(R.id.caiv_cswjfd_jcgsz)
    CarArchiveItemView caivCswjfdJcgsz;
    @BindView(R.id.caiv_cswjfd_jcgyycg)
    CarArchiveItemView caivCswjfdJcgyycg;
    @BindView(R.id.caiv_cswjhm_hbxyyzcg)
    CarArchiveItemView caivCswjhmHbxyyzcg;
    @BindView(R.id.caiv_cswddwm)
    CarArchiveItemView caivCswddwm;
    @BindView(R.id.caiv_cswjgcmsz)
    CarArchiveItemView caivCswjgcmsz;
    @BindView(R.id.caiv_cswjqhygq)
    CarArchiveItemView caivCswjqhygq;
    @BindView(R.id.caiv_cswjl_zmfjt)
    CarArchiveItemView caivCswjlZmfjt;
    @BindView(R.id.caiv_scfj_bt)
    CarArchiveItemView caivScfjBt;
    @BindView(R.id.caiv_scfj_qjd)
    CarArchiveItemView caivScfjQjd;
    @BindView(R.id.caiv_scfj_ltbs)
    CarArchiveItemView caivScfjLtbs;
    @BindView(R.id.caiv_scfj_sjjsp)
    CarArchiveItemView caivScfjSjjsp;
    @BindView(R.id.caiv_qt_qtys)
    CarArchiveItemView caivQtQtys;
    @BindView(R.id.caiv_qt_ykqjgn)
    CarArchiveItemView caivQtYkqjgn;
    @BindView(R.id.ll_commonuse_check)
    LinearLayout llCommonuseCheck;
    @BindView(R.id.tt_supply_check)
    TabTitle ttSupplyCheck;
    @BindView(R.id.ll_supply_check)
    LinearLayout llSupplyCheck;
    @BindView(R.id.ll_fdjc_check)
    LinearLayout llFdjcCheck;
    @BindView(R.id.ll_jsc_check)
    LinearLayout llJscCheck;
    @BindView(R.id.ll_qidong_check)
    LinearLayout llQidongCheck;
    @BindView(R.id.ll_lushi_check)
    LinearLayout llLushiCheck;
    @BindView(R.id.ll_dipan_check)
    LinearLayout llDipanCheck;
    @BindView(R.id.ll_gnxlbj_check)
    LinearLayout llGnxlbjCheck;
    @BindView(R.id.ll_zdpz_check)
    LinearLayout llZdpzCheck;
    @BindView(R.id.iv_multi_bitmaps)
    DrawBitmapsImageView ivMultiBitmaps;
    @BindView(R.id.rl_container)
    RelativeLayout rlContainer;
    @BindView(R.id.iv_display)
    ImageView ivDisplay;
    @BindView(R.id.iv_draw_lacquer)
    DrawBitmapsImageView ivDrawLacquer;
    @BindView(R.id.root_view_supply_check)
    LinearLayout rootViewSupplyCheck;
    @BindView(R.id.ll_auto_scroll_img_container)
    LinearLayout llAutoScrollImgContainer;


    private ViewPagerAdapter mAdapter;
    private ArrayList<String> urlList;

    private boolean SCROLLVIEW_LOCATED = false;

    private String[] errorDescs;

    //      字体大小
    private int[] textSizes = new int[]{11, 13, 20};
    //     原型图标大小
    private int[] circleSizes = new int[]{25, 30, 35};

    private EvaluateDetailResult2.DetectionBean detectionBean;

    private ArrayList<CarArchiveItemView> bodyFrameItem;
    //    车身骨架补充检查项
    private ArrayList<CarArchiveItemView> bodyFrameBCChcekItems;

    //    常用功能检查项
    private ArrayList<CarArchiveItemView> commonFunctionCheckItems;

    private String[] tempStr;

    @Override
    protected void init() {
        setContentView(R.layout.er_activity_car_archive);
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {

        vTopbar.setTitle("车辆评估详情");
        vTopbar.setLeftBack();

        bodyFrameItem = new ArrayList<>();
        bodyFrameItem.add(caivRightA);
        bodyFrameItem.add(caivRightB);
        bodyFrameItem.add(caivRightC);
        bodyFrameItem.add(caivYhxg);
        bodyFrameItem.add(caivLeftC);
        bodyFrameItem.add(caivZhxg);
        bodyFrameItem.add(caivLeftB);
        bodyFrameItem.add(caivLeftA);
        bodyFrameItem.add(caivZqzl);
        bodyFrameItem.add(caivZyl);
        bodyFrameItem.add(caivZqxg);
        bodyFrameItem.add(caivLmj);
        bodyFrameItem.add(caivYyl);
        bodyFrameItem.add(caivYqzl);
        bodyFrameItem.add(caivYqxg);

        bodyFrameBCChcekItems = new ArrayList<>();
        bodyFrameBCChcekItems.add(caivHfzlss);
        bodyFrameBCChcekItems.add(caivGzlax);
        bodyFrameBCChcekItems.add(caivGzlwgd);
        bodyFrameBCChcekItems.add(caivGzlbx);
        bodyFrameBCChcekItems.add(caivGzlsx);
        bodyFrameBCChcekItems.add(caivCnjs);
        bodyFrameBCChcekItems.add(caivCksysh);
        bodyFrameBCChcekItems.add(caivBtsyjs);
        bodyFrameBCChcekItems.add(caivCdpsx);
        bodyFrameBCChcekItems.add(caivNzntdcsx);

//        发动机舱检查
        commonFunctionCheckItems = new ArrayList<>();
        commonFunctionCheckItems.add(caivJyhrlqy);
        commonFunctionCheckItems.add(caivGgwjysl);
        commonFunctionCheckItems.add(caivSrqgsps);
        commonFunctionCheckItems.add(caivXdcdjzzfs);
        commonFunctionCheckItems.add(caivXdcdjyslqs);
        commonFunctionCheckItems.add(caivFdjpdlh);
        commonFunctionCheckItems.add(caivYglhls);
        commonFunctionCheckItems.add(caivSglhls);
        commonFunctionCheckItems.add(caivXslhps);
        commonFunctionCheckItems.add(caivFdjhmwfqr);

//      驾驶舱检查
        commonFunctionCheckItems.add(caivCnpshj);
        commonFunctionCheckItems.add(caivCnhsjps);
        commonFunctionCheckItems.add(caivCnyyw);
        commonFunctionCheckItems.add(caivYbtyyc);
        commonFunctionCheckItems.add(caivTcqbyc);
        commonFunctionCheckItems.add(caivTcmftlh);
        commonFunctionCheckItems.add(caivZczdxtyc);
        commonFunctionCheckItems.add(caivJsczkyp);
        commonFunctionCheckItems.add(caivYxzj);

//      启动检查
        commonFunctionCheckItems.add(caivClqdbsc);
        commonFunctionCheckItems.add(caivYbbzsdyc);
        commonFunctionCheckItems.add(caivFxdtdsnd);
        commonFunctionCheckItems.add(caivBcfzxtgzbzc);
        commonFunctionCheckItems.add(caivAbsUnnormal);
        commonFunctionCheckItems.add(caivKtgz);
        commonFunctionCheckItems.add(caivKtxtblr);
        commonFunctionCheckItems.add(caivFdjdsyzbwd);
        commonFunctionCheckItems.add(caivFdjyyx);
        commonFunctionCheckItems.add(caivFdjyyyClpqbzc);

//      路试检查
        commonFunctionCheckItems.add(caivFdjjsbzc);
        commonFunctionCheckItems.add(caivJsyppxx);
        commonFunctionCheckItems.add(caivZdxtgzbzc);
        commonFunctionCheckItems.add(caivBsxgzbzc);
        commonFunctionCheckItems.add(caivXcgczCldpyyx);
        commonFunctionCheckItems.add(caivXsgczClzxbwyyx);
        commonFunctionCheckItems.add(caivXsfxphdd);
        commonFunctionCheckItems.add(caivKktsfdJwtsxx);

//      底盘检查
        commonFunctionCheckItems.add(caivFdjydksl);
        commonFunctionCheckItems.add(caivBsxtsl);
        commonFunctionCheckItems.add(caivZxjbqxsd);
        commonFunctionCheckItems.add(caivSjbqxsd);
        commonFunctionCheckItems.add(caivCdzszjsk);
        commonFunctionCheckItems.add(caivJzqsy);
        commonFunctionCheckItems.add(caivJzthsh);
        commonFunctionCheckItems.add(caivCdpzjdjsx);
        commonFunctionCheckItems.add(caivPqghxyqYyhpl);

//      功能性零部件检查
        commonFunctionCheckItems.add(caivCswjfdJcgsz);
        commonFunctionCheckItems.add(caivCswjfdJcgyycg);
        commonFunctionCheckItems.add(caivCswjhmHbxyyzcg);
        commonFunctionCheckItems.add(caivCswddwm);
        commonFunctionCheckItems.add(caivCswjgcmsz);
        commonFunctionCheckItems.add(caivCswjqhygq);
        commonFunctionCheckItems.add(caivCswjlZmfjt);
        commonFunctionCheckItems.add(caivScfjBt);
        commonFunctionCheckItems.add(caivScfjQjd);
        commonFunctionCheckItems.add(caivScfjLtbs);
        commonFunctionCheckItems.add(caivScfjSjjsp);
        commonFunctionCheckItems.add(caivQtQtys);
        commonFunctionCheckItems.add(caivQtYkqjgn);


        ttAccidentCheck.setTitle("事故排查");
        ttAccidentCheck.setView(llAccidentCheck, svContent);

        ttAppearanceCheck.setTitle("外观检查");
        ttAppearanceCheck.setView(llAppearanceCheck, svContent);

        ttLacquerCheck.setTitle("漆面检查");
        ttLacquerCheck.setView(llLacquerCheck, svContent);

        ttCommonuseCheck.setTitle("常用功能检查");
        ttCommonuseCheck.setView(llCommonuseCheck, svContent);

        ttSupplyCheck.setTitle("补充检查");
        ttSupplyCheck.setView(llSupplyCheck, svContent);

    }

    @Override
    protected void initData() {

        urlList = new ArrayList<>();
        errorDescs = getResources().getStringArray(R.array.bcsm_error_item_descs);
        tempStr = new String[]{"轻微 ", "严重 ", "需换修"};
//        if ( null != getIntent().getSerializableExtra("detection")) {
//
//            detectionBean = (EvaluateDetailResult2.DetectionBean) getIntent().getSerializableExtra("detection");
//
//            displayInfo();
//
//            Log.e(TAG, "initData:  DetectionBean : " + new Gson().toJson(detectionBean));
//
//        }

    }


    private void displayInfo() {

//        重大碰撞检查
        if (null != detectionBean.getBodyframe()) {

            String[] problemDesc = getResources().getStringArray(R.array.problem_desc);

            ArrayList<Bitmap> bodyFrameBitmaps = new ArrayList<>();

            for (EvaluateDetailResult2.DetectionBean.BodyframeBean bodyframeBean : detectionBean.getBodyframe()) {

                if (bodyframeBean.getId() == 0) {
//                    if (bodyframeBean.getStatus() == 7) {
//                        caivCtzydc.showProblemStatu("不对称");
//                    }
                    if(!TextUtils.isEmpty(String.valueOf(bodyframeBean.getStatus())) && bodyframeBean.getStatus() != 0 ) {
                        if(problemDesc.length>bodyframeBean.getStatus() - 1) {
                            caivCtzydc.showProblemStatu(problemDesc[bodyframeBean.getStatus() - 1]);
                        }
                    }
                } else {
                    bodyFrameBitmaps.add(BitmapUtils.decodeSampledBitmapFromResource(this, Constants.errorImgIdList[bodyframeBean.getId() - 1]));

                    if(!TextUtils.isEmpty(String.valueOf(bodyframeBean.getStatus())) && bodyframeBean.getStatus() != 0 ) {
                        bodyFrameItem.get(bodyframeBean.getId() - 1).showProblemStatu(problemDesc[bodyframeBean.getStatus() - 1]);
                    }
                }
            }

            if (bodyFrameBitmaps.size() != 0){
                ivMultiBitmaps.setBitmaps(bodyFrameBitmaps.toArray(new Bitmap[bodyFrameBitmaps.size()]));
            }

        }

//        车身骨架补充
        if (null != detectionBean.getBodyframe_mark()) {

            for (EvaluateDetailResult2.DetectionBean.BodyframeMarkBean markBean : detectionBean.getBodyframe_mark()) {
                bodyFrameBCChcekItems.get(markBean.getId()).showProblemStatu(tempStr[markBean.getStatus() - 1]);
            }
        }


//        外观检查
        if (null != detectionBean.getApshell()) {

            for (EvaluateDetailResult2.DetectionBean.ApshellBean apshellBean : detectionBean.getApshell()) {

                addTextViewToSpecifiedPoint(CarEvaluateDetailActivity.this, Constants.errStateDESCS[apshellBean.getStatus() - 1],
                        textSizes[apshellBean.getSize() / 100 - 1], circleSizes[apshellBean.getSize() / 100 - 1],
                        apshellBean.getX() * ivDisplay.getWidth(), apshellBean.getY() * ivDisplay.getHeight(), apshellBean.getImage());

                if(!TextUtils.isEmpty(apshellBean.getImage())){
//                  添加外观检查车辆故障图片
                    urlList.add(apshellBean.getImage());
                }
            }
        }


//       缺陷图片故障预览
        if(null != urlList && urlList.size() > 0 ){

            llAutoScrollImgContainer.setVisibility(View.VISIBLE);
            tvIndicator.setText( "1/" + urlList.size());
            mAdapter = new ViewPagerAdapter(urlList, this);
            asvpImgDisplay.setAdapter(mAdapter);
            asvpImgDisplay.setOnPageChangeListener(this);
        }


//        漆面检查
        if (null != detectionBean.getPaint()) {

            int YUAN_CHANG_QI = 1, PEN_QI = 2, BAN_JIN = 3;

            ArrayList<Bitmap> lacquerBitmaps = new ArrayList<>();

            for (EvaluateDetailResult2.DetectionBean.PaintBean paintBean : detectionBean.getPaint()) {
                if (paintBean.getId()>=Constants.pqDrawablesId.length){
                    break;
                }
                if (paintBean.getStatus() == PEN_QI) {
                    lacquerBitmaps.add(BitmapUtils.decodeSampledBitmapFromResource(this, Constants.pqDrawablesId[paintBean.getId()]));
                } else if (paintBean.getStatus() == BAN_JIN) {
                    lacquerBitmaps.add(BitmapUtils.decodeSampledBitmapFromResource(this, Constants.bjDrawablesId[paintBean.getId()]));
                } else if (paintBean.getStatus() == YUAN_CHANG_QI) {
                    lacquerBitmaps.add(BitmapUtils.decodeSampledBitmapFromResource(this, Constants.ycqDrawablesId[paintBean.getId()]));
                }
            }

            if (lacquerBitmaps.size() != 0) {
                ivDrawLacquer.setBitmaps(lacquerBitmaps.toArray(new Bitmap[lacquerBitmaps.size()]));
            }
        }

//        发动机舱检查
        if (null != detectionBean.getEncomp()) {

            for (EvaluateDetailResult2.DetectionBean.EncompBean encompBean : detectionBean.getEncomp()) {

                if (encompBean.getStatus() != 0) {

                    commonFunctionCheckItems.get(encompBean.getId() - 1).showProblemStatu(tempStr[encompBean.getStatus() - 1]);
                    if (!TextUtils.isEmpty(encompBean.getImage())) {
                        commonFunctionCheckItems.get(encompBean.getId() - 1).showPhotoIcon(this, encompBean.getImage());
                    }
                }
            }
        }


//       驾驶舱检查
        if (null != detectionBean.getCockpit()) {
            for (EvaluateDetailResult2.DetectionBean.CockpitBean cockpitBean : detectionBean.getCockpit()) {

                if (cockpitBean.getStatus() != 0) {
                    commonFunctionCheckItems.get(cockpitBean.getId() - 1).showProblemStatu(tempStr[cockpitBean.getStatus() - 1]);
                    if (!TextUtils.isEmpty(cockpitBean.getImage())) {
                        commonFunctionCheckItems.get(cockpitBean.getId() - 1).showPhotoIcon(this, cockpitBean.getImage());
                    }
                }
            }
        }

//      启动检查
        if (null != detectionBean.getIgnition()) {
            for (EvaluateDetailResult2.DetectionBean.IgnitionBean ignitionBean : detectionBean.getIgnition()) {
                if (ignitionBean.getStatus() != 0) {
                    commonFunctionCheckItems.get(ignitionBean.getId() - 1).showProblemStatu(tempStr[ignitionBean.getStatus() - 1]);
                    if (!TextUtils.isEmpty(ignitionBean.getImage())) {
                        commonFunctionCheckItems.get(ignitionBean.getId() - 1).showPhotoIcon(this, ignitionBean.getImage());
                    }
                }
            }
        }

//       路试检查
        if (null != detectionBean.getRacing()) {
            for (EvaluateDetailResult2.DetectionBean.RacingBean racingBean : detectionBean.getRacing()) {
                if (racingBean.getStatus() != 0) {
                    commonFunctionCheckItems.get(racingBean.getId() - 1).showProblemStatu(tempStr[racingBean.getStatus() - 1]);
                    if (!TextUtils.isEmpty(racingBean.getImage())) {
                        commonFunctionCheckItems.get(racingBean.getId() - 1).showPhotoIcon(this, racingBean.getImage());
                    }
                }
            }
        }

//       底盘检查
        if (null != detectionBean.getChassis()) {
            for (EvaluateDetailResult2.DetectionBean.ChassisBean chassisBean : detectionBean.getChassis()) {
                if (chassisBean.getStatus() != 0) {
                    commonFunctionCheckItems.get(chassisBean.getId() - 1).showProblemStatu(tempStr[chassisBean.getStatus() - 1]);
                    if (!TextUtils.isEmpty(chassisBean.getImage())) {
                        commonFunctionCheckItems.get(chassisBean.getId() - 1).showPhotoIcon(this, chassisBean.getImage());
                    }
                }
            }
        }

//      功能性零部件检查
        if (null != detectionBean.getParts()) {
            for (EvaluateDetailResult2.DetectionBean.PartsBean partsBean : detectionBean.getParts()) {
                if (partsBean.getStatus() != 0) {
                    commonFunctionCheckItems.get(partsBean.getId() - 1).showProblemStatu(tempStr[partsBean.getStatus() - 1]);
                    if (!TextUtils.isEmpty(partsBean.getImage())) {
                        commonFunctionCheckItems.get(partsBean.getId() - 1).showPhotoIcon(this, partsBean.getImage());
                    }
                }
            }
        }


//        动态添加补充说明视图
//        外观与车体补充说明
        if (null != detectionBean.getApshell_mark() && detectionBean.getApshell_mark().size() != 0) {

            if (rootViewSupplyCheck.getVisibility() != View.VISIBLE)
                rootViewSupplyCheck.setVisibility(View.VISIBLE);

            llSupplyCheck.addView(addSubTitle("外观与车体"));

            for (EvaluateDetailResult2.DetectionBean.ApshellMarkBean markBean : detectionBean.getApshell_mark()) {
                if (markBean.getStatus() != 0)
                    llSupplyCheck.addView(addCarArchiveCheckItemView(errorDescs[markBean.getId()], tempStr[markBean.getStatus() - 1]));
            }
        }

//        发动机舱补充说明
        if (null != detectionBean.getEncomp_mark() && detectionBean.getEncomp_mark().size() != 0) {

            if (rootViewSupplyCheck.getVisibility() != View.VISIBLE)
                rootViewSupplyCheck.setVisibility(View.VISIBLE);

            llSupplyCheck.addView(addSubTitle("发动机舱"));

            for (EvaluateDetailResult2.DetectionBean.EncompMarkBean markBean : detectionBean.getEncomp_mark()) {
                if (markBean.getStatus() != 0)
                    llSupplyCheck.addView(addCarArchiveCheckItemView(errorDescs[markBean.getId()], tempStr[markBean.getStatus() - 1]));
            }
        }

//        驾驶舱补充说明
        if (null != detectionBean.getCockpit_mark() && detectionBean.getCockpit_mark().size() != 0) {

            if (rootViewSupplyCheck.getVisibility() != View.VISIBLE)
                rootViewSupplyCheck.setVisibility(View.VISIBLE);

            llSupplyCheck.addView(addSubTitle("驾驶舱"));

            for (EvaluateDetailResult2.DetectionBean.CockpitMarkBean markBean : detectionBean.getCockpit_mark()) {
                if (markBean.getStatus() != 0)
                    llSupplyCheck.addView(addCarArchiveCheckItemView(errorDescs[markBean.getId()], tempStr[markBean.getStatus() - 1]));
            }
        }

        //    启动检查补充说明
        if (null != detectionBean.getIgnition_mark() && detectionBean.getIgnition_mark().size() != 0) {

            if (rootViewSupplyCheck.getVisibility() != View.VISIBLE)
                rootViewSupplyCheck.setVisibility(View.VISIBLE);

            llSupplyCheck.addView(addSubTitle("启动"));

            for (EvaluateDetailResult2.DetectionBean.IgnitionMarkBean markBean : detectionBean.getIgnition_mark()) {
                if (markBean.getStatus() != 0)
                    llSupplyCheck.addView(addCarArchiveCheckItemView(errorDescs[markBean.getId()], tempStr[markBean.getStatus() - 1]));
            }
        }

        //        路试检查补充说明
        if (null != detectionBean.getRacing_mark() && detectionBean.getRacing_mark().size() != 0) {

            if (rootViewSupplyCheck.getVisibility() != View.VISIBLE)
                rootViewSupplyCheck.setVisibility(View.VISIBLE);

            llSupplyCheck.addView(addSubTitle("路试"));

            for (EvaluateDetailResult2.DetectionBean.RacingMarkBean markBean : detectionBean.getRacing_mark()) {
                if (markBean.getStatus() != 0)
                    llSupplyCheck.addView(addCarArchiveCheckItemView(errorDescs[markBean.getId()], tempStr[markBean.getStatus() - 1]));
            }
        }

        //        底盘补充说明
        if (null != detectionBean.getChassis_mark() && detectionBean.getChassis_mark().size() != 0) {

            if (rootViewSupplyCheck.getVisibility() != View.VISIBLE)
                rootViewSupplyCheck.setVisibility(View.VISIBLE);

            llSupplyCheck.addView(addSubTitle("底盘"));

            for (EvaluateDetailResult2.DetectionBean.ChassisMarkBean markBean : detectionBean.getChassis_mark()) {
                if (markBean.getStatus() != 0)
                    llSupplyCheck.addView(addCarArchiveCheckItemView(errorDescs[markBean.getId()], tempStr[markBean.getStatus() - 1]));
            }
        }

        //        功能性零部件补充说明
        if (null != detectionBean.getParts_mark() && detectionBean.getParts_mark().size() != 0) {

            if (rootViewSupplyCheck.getVisibility() != View.VISIBLE)
                rootViewSupplyCheck.setVisibility(View.VISIBLE);

            llSupplyCheck.addView(addSubTitle("功能性零部件"));

            for (EvaluateDetailResult2.DetectionBean.PartsMarkBean markBean : detectionBean.getParts_mark()) {
                if (markBean.getStatus() != 0)
                    llSupplyCheck.addView(addCarArchiveCheckItemView(errorDescs[markBean.getId()], tempStr[markBean.getStatus() - 1]));
            }
        }
    }


    //    添加补充说明子标题
    public View addSubTitle(String subTitleDesc) {
        LinearLayout itemTitle = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.er_car_archive_detail_bcjc_kind_title, null);
        ((TextView) itemTitle.findViewById(R.id.tv_kind_title)).setText(subTitleDesc);
        return itemTitle;
    }


    //    添加检查项视图
    public View addCarArchiveCheckItemView(String itemDesc, String errorDesc) {

        CarArchiveItemView itemView = new CarArchiveItemView(this);
        itemView.showIndexView();
        itemView.setNumberIndex(" ");
        itemView.setItemDesc(itemDesc);
        itemView.showProblemStatu(errorDesc);
        return itemView;
    }

    public TextView addTextViewToSpecifiedPoint(Context context, String textDesc, int textSize, int circleSize, float x, float y, String imgPath) {

        TextView tv = new TextView(context);
        tv.setText(textDesc);
        tv.setTextColor(Color.WHITE);

        if (TextUtils.isEmpty(imgPath))
            tv.setBackgroundResource(R.drawable.small_red_circle);
        else
            tv.setBackgroundResource(R.drawable.small_golden_circle);

        tv.setTextSize(textSize);
        tv.setGravity(Gravity.CENTER);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ConvertUtils.dp2px(circleSize), ConvertUtils.dp2px(circleSize));


        layoutParams.leftMargin = (int) x - ConvertUtils.dp2px(circleSize / 2);
        layoutParams.topMargin = (int) y - ConvertUtils.dp2px(circleSize / 2);

        tv.setLayoutParams(layoutParams);
        rlContainer.addView(tv);

        Log.e(TAG, "addTextViewToSpecifiedPoint: 添加TextView ");

        return tv;

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.caiv_right_a:
                ToastUtil.showToast("CAIV_A");
                caivRightA.showProblemStatu("轻微");
                break;
            case R.id.caiv_right_b:
                ToastUtil.showToast("CAIV_B");
                caivRightA.showProblemStatu("严重");
                break;

            default:
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        asvpImgDisplay.startAutoScroll();
    }

    @Override
    protected void onStop() {
        super.onStop();
        asvpImgDisplay.stopAutoScroll();
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
//        super.onWindowFocusChanged(hasFocus);

        if (-1 != getIntent().getIntExtra("VIEW_ID", -1) && hasFocus && !SCROLLVIEW_LOCATED) {
            if (hasFocus && null != getIntent().getSerializableExtra("detection")) {

                detectionBean = (EvaluateDetailResult2.DetectionBean) getIntent().getSerializableExtra("detection");

                displayInfo();

                Log.e(TAG, "initData:  DetectionBean : " + new Gson().toJson(detectionBean));

            }

            switch (getIntent().getIntExtra("VIEW_ID", -1)) {

                case R.id.rl_csgj:
                    locateTo(llZdpzCheck);
                    break;
                case R.id.rl_wg:
                    locateTo(ttAppearanceCheck);
                    break;

                case R.id.rl_fdjc:
                    locateTo(llFdjcCheck);
                    break;
                case R.id.rl_jsc:
                    locateTo(llJscCheck);
                    break;
                case R.id.rl_qd:
                    locateTo(llQidongCheck);
                    break;
                case R.id.rl_gnx_lbj:
                    locateTo(llGnxlbjCheck);
                    break;
                case R.id.rl_ls:
                    locateTo(llLushiCheck);
                    break;
                case R.id.rl_dp:
                    locateTo(llDipanCheck);
                    break;

                default:
                    break;
            }
            SCROLLVIEW_LOCATED = true;
        }

    }

    /**
     * ScrollView滚动到指定View的坐标
     *
     * @param view
     */
    private void locateTo(final View view) {

        final int[] location = new int[2];
        view.getLocationOnScreen(location);
        Log.e(TAG, "locateTo: " + location[0] + " " + location[1]);
        if(llAutoScrollImgContainer.getVisibility()==View.VISIBLE){
            llAutoScrollImgContainer.post(new Runnable() {
                @Override
                public void run() {
                    int height = llAutoScrollImgContainer.getHeight();
                    svContent.smoothScrollTo(0, location[1] +
                            height- ((ScreenUtil.getStatusBarHeight() != -1) ? ScreenUtil.getStatusBarHeight() : 0) - vTopbar.getMeasuredHeight());
                }
            });
        }else {
            svContent.smoothScrollTo(0, location[1] - ((ScreenUtil.getStatusBarHeight() != -1) ? ScreenUtil.getStatusBarHeight() : 0) - vTopbar.getMeasuredHeight());
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        tvIndicator.setText((position) % urlList.size() + 1 + "/" + urlList.size());
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }


    @Override
    public void onIconClick(int carArchiveItemViewID) {

        switch (carArchiveItemViewID) {

            case R.id.caiv_jyhrlqy:
                previewImgWithImgPath(caivJyhrlqy.getImgPath());
                break;
            case R.id.caiv_ggwjysl:
                previewImgWithImgPath(caivGgwjysl.getImgPath());
                break;
            case R.id.caiv_srqgsps:
                previewImgWithImgPath(caivSrqgsps.getImgPath());
                break;
            case R.id.caiv_xdcdjzzfs:
                previewImgWithImgPath(caivXdcdjzzfs.getImgPath());
                break;
            case R.id.caiv_xdcdjyslqs:
                previewImgWithImgPath(caivXdcdjyslqs.getImgPath());
                break;
            case R.id.caiv_fdjpdlh:
                previewImgWithImgPath(caivFdjpdlh.getImgPath());
                break;
            case R.id.caiv_yglhls:
                previewImgWithImgPath(caivYglhls.getImgPath());
                break;
            case R.id.caiv_sglhls:
                previewImgWithImgPath(caivSglhls.getImgPath());
                break;
            case R.id.caiv_xslhps:
                previewImgWithImgPath(caivXslhps.getImgPath());
                break;
            case R.id.caiv_fdjhmwfqr:
                previewImgWithImgPath(caivFdjhmwfqr.getImgPath());
                break;
            case R.id.caiv_cnpshj:
                previewImgWithImgPath(caivCnpshj.getImgPath());
                break;
            case R.id.caiv_cnhsjps:
                previewImgWithImgPath(caivCnhsjps.getImgPath());
                break;
            case R.id.caiv_cnyyw:
                previewImgWithImgPath(caivCnyyw.getImgPath());
                break;
            case R.id.caiv_ybtyyc:
                previewImgWithImgPath(caivYbtyyc.getImgPath());
                break;
            case R.id.caiv_tcqbyc:
                previewImgWithImgPath(caivTcqbyc.getImgPath());
                break;
            case R.id.caiv_tcmftlh:
                previewImgWithImgPath(caivTcmftlh.getImgPath());
                break;
            case R.id.caiv_zczdxtyc:
                previewImgWithImgPath(caivZczdxtyc.getImgPath());
                break;
            case R.id.caiv_jsczkyp:
                previewImgWithImgPath(caivJsczkyp.getImgPath());
                break;
            case R.id.caiv_yxzj:
                previewImgWithImgPath(caivYxzj.getImgPath());
                break;
            case R.id.caiv_clqdbsc:
                previewImgWithImgPath(caivClqdbsc.getImgPath());
                break;
            case R.id.caiv_ybbzsdyc:
                previewImgWithImgPath(caivYbbzsdyc.getImgPath());
                break;
            case R.id.caiv_fxdtdsnd:
                previewImgWithImgPath(caivFxdtdsnd.getImgPath());
                break;
            case R.id.caiv_bcfzxtgzbzc:
                previewImgWithImgPath(caivBcfzxtgzbzc.getImgPath());
                break;
            case R.id.caiv_abs_unnormal:
                previewImgWithImgPath(caivAbsUnnormal.getImgPath());
                break;
            case R.id.caiv_ktgz:
                previewImgWithImgPath(caivKtgz.getImgPath());
                break;
            case R.id.caiv_ktxtblr:
                previewImgWithImgPath(caivKtxtblr.getImgPath());
                break;
            case R.id.caiv_fdjdsyzbwd:
                previewImgWithImgPath(caivFdjdsyzbwd.getImgPath());
                break;
            case R.id.caiv_fdjyyx:
                previewImgWithImgPath(caivFdjyyx.getImgPath());
                break;
            case R.id.caiv_fdjyyy_clpqbzc:
                previewImgWithImgPath(caivFdjyyyClpqbzc.getImgPath());
                break;
            case R.id.caiv_fdjjsbzc:
                previewImgWithImgPath(caivFdjjsbzc.getImgPath());
                break;
            case R.id.caiv_jsyppxx:
                previewImgWithImgPath(caivJsyppxx.getImgPath());
                break;
            case R.id.caiv_zdxtgzbzc:
                previewImgWithImgPath(caivZdxtgzbzc.getImgPath());
                break;
            case R.id.caiv_bsxgzbzc:
                previewImgWithImgPath(caivBsxgzbzc.getImgPath());
                break;
            case R.id.caiv_xcgcz_cldpyyx:
                previewImgWithImgPath(caivXcgczCldpyyx.getImgPath());
                break;
            case R.id.caiv_xsgcz_clzxbwyyx:
                previewImgWithImgPath(caivXsgczClzxbwyyx.getImgPath());
                break;
            case R.id.caiv_xsfxphdd:
                previewImgWithImgPath(caivXsfxphdd.getImgPath());
                break;
            case R.id.caiv_kktsfd_jwtsxx:
                previewImgWithImgPath(caivKktsfdJwtsxx.getImgPath());
                break;
            case R.id.caiv_fdjydksl:
                previewImgWithImgPath(caivFdjydksl.getImgPath());
                break;
            case R.id.caiv_bsxtsl:
                previewImgWithImgPath(caivBsxtsl.getImgPath());
                break;
            case R.id.caiv_zxjbqxsd:
                previewImgWithImgPath(caivZxjbqxsd.getImgPath());
                break;
            case R.id.caiv_sjbqxsd:
                previewImgWithImgPath(caivSjbqxsd.getImgPath());
                break;
            case R.id.caiv_cdzszjsk:
                previewImgWithImgPath(caivCdzszjsk.getImgPath());
                break;
            case R.id.caiv_jzqsy:
                previewImgWithImgPath(caivJzqsy.getImgPath());
                break;
            case R.id.caiv_jzthsh:
                previewImgWithImgPath(caivJzthsh.getImgPath());
                break;
            case R.id.caiv_cdpzjdjsx:
                previewImgWithImgPath(caivCdpzjdjsx.getImgPath());
                break;
            case R.id.caiv_pqghxyq_yyhpl:
                previewImgWithImgPath(caivPqghxyqYyhpl.getImgPath());
                break;
            case R.id.caiv_cswjfd_jcgsz:
                previewImgWithImgPath(caivCswjfdJcgsz.getImgPath());
                break;
            case R.id.caiv_cswjfd_jcgyycg:
                previewImgWithImgPath(caivCswjfdJcgyycg.getImgPath());
                break;
            case R.id.caiv_cswjhm_hbxyyzcg:
                previewImgWithImgPath(caivCswjhmHbxyyzcg.getImgPath());
                break;
            case R.id.caiv_cswddwm:
                previewImgWithImgPath(caivCswddwm.getImgPath());
                break;
            case R.id.caiv_cswjgcmsz:
                previewImgWithImgPath(caivCswjgcmsz.getImgPath());
                break;
            case R.id.caiv_cswjqhygq:
                previewImgWithImgPath(caivCswjqhygq.getImgPath());
                break;
            case R.id.caiv_cswjl_zmfjt:
                previewImgWithImgPath(caivCswjlZmfjt.getImgPath());
                break;
            case R.id.caiv_scfj_bt:
                previewImgWithImgPath(caivScfjBt.getImgPath());
                break;
            case R.id.caiv_scfj_qjd:
                previewImgWithImgPath(caivScfjQjd.getImgPath());
                break;
            case R.id.caiv_scfj_ltbs:
                previewImgWithImgPath(caivScfjLtbs.getImgPath());
                break;
            case R.id.caiv_scfj_sjjsp:
                previewImgWithImgPath(caivScfjSjjsp.getImgPath());
                break;
            case R.id.caiv_qt_qtys:
                previewImgWithImgPath(caivQtQtys.getImgPath());
                break;
            case R.id.caiv_qt_ykqjgn:
                previewImgWithImgPath(caivQtYkqjgn.getImgPath());
                break;

            default:
                break;
        }
    }


    private void previewImgWithImgPath(String imgPath) {

        Intent intent = new Intent(this, PhotoPreViewActivity.class);
        intent.putExtra("IMG_PATH", imgPath);
        intent.putExtra("SHOW_DELETE_BTN", false);
        startActivity(intent);
    }

}
